package com.bike.bikeserver.controller.backend;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.bike.bikeserver.common.annotation.OperationLog;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.Rewards;
import com.bike.bikeserver.service.IRewardsService;
import com.bike.bikeserver.service.impl.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.bike.bikeserver.constant.Constants.*;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/19 11:15
 */
@RestController
@RequestMapping("back/rewards")
public class BackRewardsController
{
    @Autowired
    IRewardsService rewardsService;
    @Autowired
    SysRoleService sysRoleService;

    /**
     * 获取所有奖券信息
     *
     * @return
     */
    @GetMapping("getRewardsList")
    public CommonResult getRewardsList()
    {
        return rewardsService.getRewardsList();
    }

    /**
     * 根据奖券名模糊查询
     *
     * @param rewardsName
     * @return
     */
    @OperationLog(value = "根据奖券名模糊查询奖券信息:rewards")
    @GetMapping("getRewardsLikeName")
    public CommonResult getRewardsLikeName(@RequestParam("rewardsName") String rewardsName)
    {
        return rewardsService.getRewardsLikeName(rewardsName);
    }

    /**
     * 更新奖券信息
     *
     * @param rewards
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "根据id更新奖券信息:rewards")
    @PutMapping("editRewardsById")
    public CommonResult editRewardsById(@RequestBody Rewards rewards)
    {
        return rewardsService.editRewardsById(rewards);
    }

    /**
     * 删除奖券
     *
     * @param rewards
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "根据id删除奖券:rewards")
    @DeleteMapping("deleteRewardsById")
    public CommonResult deleteRewardsById(@RequestBody Rewards rewards)
    {
        return rewardsService.deleteRewardsById(rewards);
    }

    /**
     * 添加奖券
     *
     * @param rewards
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_EDIT, USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog(value = "新增奖券:rewards")
    @PostMapping("addRewards")
    public CommonResult addRewards(@RequestBody Rewards rewards)
    {
        return rewardsService.addRewards(rewards);
    }

}
